﻿using Aishow.BLL;
using Aishow.Common.Vod;
using Aishow.IBLL;
using Aishow.Model;
using Aishow.Model.OperResult;
using Newtonsoft.Json;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;

namespace Aishow.Website
{
    /// <summary>
    /// VideoUploadHandler 的摘要说明
    /// </summary>
    public class VideoUploadHandler : IHttpHandler
    {
        /// <summary>
        /// 处理请求
        /// </summary>
        /// <param name="context"></param>
        public void ProcessRequest(HttpContext context)
        {
            //HttpUtility.UrlEncode()
            // 读取参数
            string fileName = HttpUtility.UrlDecode(context.Request.QueryString["filename"]);
            string headline = HttpUtility.UrlDecode(context.Request.QueryString["headline"]);
            if (string.IsNullOrWhiteSpace(headline))
            {
                headline = "没有视频标题";
            }
            string location = HttpUtility.UrlDecode(context.Request.QueryString["location"]);
            // 读取用户Id
            TBUsers user = IdentityManager.ReadUser();
            int userId = user.Id;
            // 媒体处理
            IVideoManager videoManager = new VideoManager();
            OperResult<CreateUploadVideoResult> createResult = videoManager.ToBeUpload(userId, fileName, headline, location);
            // 输出
            string jsonString = JsonConvert.SerializeObject(createResult.ReadResult());
            context.Response.ContentType = "text/plain";
            context.Response.Write(jsonString);
            context.Response.End();
        }

        public bool IsReusable
        {
            get
            {
                return false;
            }
        }
    }
}